<!DOCTYPE html>
<!--解决idea thymeleaf 表达式模板报红波浪线-->
<!--suppress ALL -->
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 引入公用部分 -->
    <!--<script th:replace="head::static"></script>-->
    <script src="/jquery/jquery.js"></script>
    <link href="/layui/css/layui.css" rel="stylesheet" type="text/css">
    <script src="/layui/layui.js"></script>
    <style>
        .layui-form-checked span, .layui-form-checked:hover span {
            background-color: #009688;
        }

        .div{
            float:left;
            margin-left:28px;
            width:190px;
            margin-top:20px;
        }

    </style>
</head>
<body>
    <div class="layui-form">

        <div class="layui-form-item" pane="" style="width: 700px;padding:50px 30px;margin-top:20px;">
            <div id="role_id">

            </div>

            <button type="button" class="layui-btn layui-btn-xs" style="margin-top: 40px; margin-left: 90%;" onclick="sure()">确定</button>
        </div>
    </div>
    <script>
        //一般直接写在一个js文件中
        layui.use('form', function(){
            var form = layui.form;
            var roleHtml = '';

            $.ajax({
                url : "/seller/info/list/serviceType",
                type : "post",
                dataType : "json",
                success : function(res){
                    for(var i = 0;i<res.data.length;i++){
                        roleHtml += "<div class='div'><input type='checkbox'  name='role_id' title='" + res.data[i] + "' value='" + res.data[i] + "'></div>";
                    }

                    //渲染数据
                    document.getElementById('role_id').innerHTML  = roleHtml;
                    form.render('checkbox');
                }
            });


        });

        function sure(){
            layer.confirm('确认通过该认证吗？', function (index) {
                var sellerId = window.location.href.split("?")[1];

                var serviceTypes = "";

                $('input[type=checkbox]:checked').each(function() {
                    serviceTypes += $(this).val() + ",";
                });

                //向服务端发送删除指令
                $.post("/seller/info/dealSellerInfo",
                    {sellerId:sellerId,isAuthentication:'Y',serviceType:serviceTypes.substring(0,serviceTypes.length-1)}, function (data) {
                        if(data.flag){
                            layer.msg("保存成功", {icon: 1, time: 2000}, function(){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                window.parent.$("#queryStaY").click();
                            });
                        } else {
                            layer.msg("保存失败!", {icon: 5});
                        }
                    })
            });
        }

</script>
</body>
</html>